********************************************************************************
* TABLE 7: Patient characteristics by bargaining power status & by type of provider
* AND ESTIMATING RPM BY INTRA-HOUSEHOLD BARGAINING BARGANINING POWER 
********************************************************************************

 use "data_acute_illness_patients_mixedlogit_vs4.dta", clear


****************************************************************************
* RECALL THE HIGH/LOW BARGANING POWER INDICATORS
****************************************************************************
/*

gen age_diff = agehh-agess
replace age_diff = . if femaleheadh==1


label var edudifflargep50 "dummy, difference hh-spouse education is larger than p50"
label var agedifflargep50 "dummy, difference hh-spouse age is larger than p50"
label var agedifflarge    "dummy, difference hh-spouse age is larger than mean"

gen ageh = age if relation_head==1 & gender==1 //* male*//
egen agehh = mean(ageh), by(hh_id09)

gen ages = age if relation_head==2 & gender==2 
egen agess = mean(ages), by(hh_id09)

gen children = (relation_head==3 & age <=18)
*/

************************************************
* PROXIES FOR BARGAINING POWER
************************************************
describe  income* weekly*

* income differences is a better measure than the ratio because there are significant women earning zero which means the ratio income(man)/sincome(woman) is indeterminate
********************************************************************
* BASELINE MODEL: on SPOUSE SAMPLE
*********************************************************************
sum age_diff agediff*
	 
tab agedifflargep50, miss
tab agedifflarge, miss
tab agedifflargep75, miss
	 
drop p_female
drop spouse
	 

* BARGAINING HETEROGENEITY: PROXY BY WEEKLY INCOME DIFERENTIAL 50th percentile
 
 	 preserve 
	 set seed 5479023
	 gen islam = (q01_16==3 & q01_16 <.)

	 *gen p_ = p_
	 gen p_lowbargain  = p_*weeklydifflargep50
	 gen p_female = p_*female
	 gen p_female_lowbargain = p_*female*weeklydifflargep50
	 	  
    * consider only the sample of spouses
	gen spouse = (relation_head==1 | relation_head==2)
	tab relation_head spouse
	
	 matrix b55g = b50[1,1..6], 0.0,  0.003, 0.26, 0.001, 0.0, 0.0, 0.0, 0.0,    0.001, 0.01, 0.0, 0.0, 0.0, 0.0, 0.0 
	 
	 mixlogit d_  dist_dw_hf_2 dist_22   nu_8d alt2-alt4 nu_8dsq if spouse==1 , group(choicesit) id(idid) cluster(hh_id09)  rand(doctor_tot  generator2009 beds p_  p_lowbargain p_female p_female_lowbargain ) from(b55g, copy)
	  	gen sample_with_braginingdata =  e(sample)	 
		tab sample_with_braginingdata
	  
	  * Among Muslim population using the same sample of observations  -- the heterogeneity female-low bargain disappears
	  mixlogit d_  dist_dw_hf_2 dist_22   nu_8d alt2-alt4 nu_8dsq if spouse==1 & islam==1, group(choicesit) id(idid) cluster(hh_id09)  rand(doctor_tot  generator2009 beds p_  p_lowbargain p_female p_female_lowbargain ) from(b55g, copy)
	  	   
	 mixlpred PR00, nrep(500)
	 est store a1 
    restore

 
  * BARGAINING HETEROGENEITY: PROXY BY AGE DIFERENTIAL 50th percentile

	 preserve 
	 set seed 5647825
	 *gen islam = (q01_16==3 & q01_16 <.)

	 *gen p_ = p_
	 gen p_lowbargain  = p_*agedifflarge
	 gen p_female = p_*female
	 gen p_female_lowbargain = p_*female*agedifflarge
	 	  
    * consider only the sample of spouses
	gen spouse = (relation_head==1 | relation_head==2)
	tab relation_head spouse
	
	 matrix b55g = b50[1,1..6], 0.0,  0.003, 0.26, 0.001, 0.0, 0.0, 0.0, 0.0,    0.001, 0.01, 0.0, 0.0, 0.0, 0.0, 0.0 
	 
	mixlogit d_  dist_dw_hf_2 dist_22   nu_8d alt2-alt4 nu_8dsq if spouse==1 , group(choicesit) id(idid) cluster(hh_id09)  rand(doctor_tot  generator2009 beds p_  p_lowbargain p_female p_female_lowbargain ) from(b55g, copy)
	gen sample_with_braginingdata =  e(sample)	 
	*mixlogit d_  dist_dw_hf_2 dist_22   nu_8d alt2-alt4 nu_8dsq if spouse==1 & islam==1, group(choicesit) id(idid) cluster(hh_id09)  rand(doctor_tot  generator2009 beds p_  p_lowbargain p_female p_female_lowbargain ) from(b55g, copy)
	  
	 mixlpred PR0, nrep(500)
	 est store b1
	 save "tempdata_mixedlogitboot_wemp.dta", replace
    restore

	
	
	* AGE DIFFERENTIAL + price*(age of husband in hh) + price*(age of husband in hh)* female
	preserve
	set seed 5479023

	 *gen p_ = p_
	 gen p_lowbargain  = p_*agedifflarge
	 gen p_female = p_*female
	 gen p_female_lowbargain = p_*female*agedifflarge
	 gen p_agehusband = p_*agehh
	 gen p_agehusb_female = p_*agehh*female
	 	  
    * consider only the spouses
	gen spouse = (relation_head==1 | relation_head==2)
	tab relation_head spouse
	
	 matrix b56g = b50[1,1..6], 0.003, 0.26, 0.001, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,     0.001, 0.01, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 
	 
	 mixlogit d_  dist_dw_hf_2 dist_22   nu_7d alt2-alt4   if spouse==1 , group(choicesit) id(idid) cluster(hh_id09) rand(doctor_tot  generator2009 beds p_  p_lowbargain p_female p_female_lowbargain p_agehusband p_agehusb_female) from(b56g, copy)
	  
	 mixlpred PR00, nrep(500)
	 est store a3 
    restore
	
	* AGE DIFFERENTIAL + price*(age of wife in hh) + price*(age of wife in hh)* female 
	preserve 
	set seed 5479023

	 *gen p_ = p_
	 gen p_lowbargain  = p_*agedifflarge
	 gen p_female = p_*female
	 gen p_female_lowbargain = p_*female*agedifflarge
	 gen p_agewife = p_*agess
	 gen p_agewife_female = p_*agess*female
	 	  
    * consider only the spouses
	gen spouse = (relation_head==1 | relation_head==2)
	tab relation_head spouse
	
	 matrix b56g = b50[1,1..6], 0.003, 0.26, 0.001, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,     0.001, 0.01, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 
	 
	 mixlogit d_  dist_dw_hf_2 dist_22   nu_7d alt2-alt4  if spouse==1 , group(choicesit) id(idid) cluster(hh_id09)  rand(doctor_tot  generator2009 beds p_  p_lowbargain p_female p_female_lowbargain p_agewife p_agewife_female) from(b56g, copy)
	  
	 mixlpred PR00, nrep(500)
	 est store a2 
    restore


	* Table A.8: Robustness tests for reviewer answer: AGE DIFFERENTIAL + price*(# of children in hh) + price*(# of children in hh)* female
	preserve
	set seed 5479023

	 *gen p_ = p_
	 gen p_lowbargain  = p_*agedifflarge
	 gen p_female = p_*female
	 gen p_female_lowbargain = p_*female*agedifflarge
	 gen p_agehusband = p_*agehh
	 gen p_agehusb_female = p_*agehh*female
	 gen p_nochild        = p_*no_child
	 gen p_nochild_female = p_*no_child*female
	 
    * consider only the spouses
	gen spouse = (relation_head==1 | relation_head==2)
	tab relation_head spouse
	
	 matrix b56g = b50[1,1..6], 0.0,  0.003, 0.26, 0.001, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,     0.001, 0.01, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 
	 
	 mixlogit d_  dist_dw_hf_2 dist_22   nu_8d  alt2-alt4  nu_8dsq if spouse==1 , group(choicesit) id(idid) cluster(hh_id09) rand(doctor_tot  generator2009 beds p_  p_lowbargain p_female p_female_lowbargain p_nochild p_nochild_female) from(b56g, copy)
	  
	 mixlpred PR00, nrep(500)
	 est store a3 
    restore

	* 
	* Table A.9: Robustness tests for reviewer answer: AGE DIFFERENTIAL + price*(# of children above median) + price*(# of children above median)* female
preserve
	collapse no_child altHF age if d_==1, by(id)
	sum no_child , det
	scalar median_no_child = r(p50)
	scalar list median_no_child
	count if no_child > median_no_child & no_child < .   /* 585/1701*/
	bys altHF: count if  no_child > median_no_child & no_child < .  
	bys altHF: count if  no_child < . 
restore

gen num_kids_above_median = (no_child > median_no_child)
 
	 preserve 
	 set seed 5479023
	 capture drop p_female spouse

	 *gen p_ = p_
	 gen p_lowbargain  = p_*agedifflarge
	 gen p_female = p_*female
	 gen p_female_lowbargain = p_*female*agedifflarge
	 gen p_num_kids_above_median  = p_*num_kids_above_median
	 gen p_female_num_kids_above_median = p_*female*num_kids_above_median
	 	  
    * consider only the sample of spouses
	gen spouse = (relation_head==1 | relation_head==2)
	tab relation_head spouse
	
	 matrix b56g = b50[1,1..6], 0.0,  0.003, 0.26, 0.001, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,     0.001, 0.01, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 
	 
	 mixlogit d_  dist_dw_hf_2 dist_22   nu_8d alt2-alt4 nu_8dsq if spouse==1 , group(choicesit) id(idid) cluster(hh_id09)  rand(doctor_tot  generator2009 beds p_  p_lowbargain p_female p_female_lowbargain  p_num_kids_above_median p_female_num_kids_above_median ) from(b56g, copy)
	  	   
	 mixlpred PR00, nrep(500)
	 est store a1 
    restore
	
	
	* Table A.9: Robustness tests for reviewer answer: AGE DIFFERENTIAL + price*(women above reproductive age) + price*(women above reproductive age)* female
	preserve
	set seed 5479023
	
gen above_reproductive = (agess > 45 )

	 *gen p_ = p_
	 gen p_lowbargain  = p_*agedifflarge
	 gen p_female = p_*female
	 gen p_female_lowbargain = p_*female*agedifflarge
	 gen p_above_reproductive = p_*above_reproductive
	 gen p_above_reproductive_female = p_*above_reproductive*female
	 
    * consider only the spouses
	gen spouse = (relation_head==1 | relation_head==2)
	tab relation_head spouse
	
	 matrix b56g = b50[1,1..6], 0.0,  0.003, 0.26, 0.001, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,     0.001, 0.01, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 
	 
	 mixlogit d_  dist_dw_hf_2 dist_22   nu_8d  alt2-alt4  nu_8dsq if spouse==1 , group(choicesit) id(idid) cluster(hh_id09) rand(doctor_tot  generator2009 beds p_  p_lowbargain p_female p_female_lowbargain p_above_reproductive p_above_reproductive_female) from(b56g, copy)
	  
	 mixlpred PR00, nrep(500)
	 est store a3 
    restore

	